﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WcfGeebaServer.ContentManage;
using WcfGeebaServer.Users;
using WcfGeebaServer.Policies;

namespace TestGeeba
{
    /// <summary>
    /// This is a test class for GForum and is intended
    /// to contain all GForum Unit Tests
    /// </summary>
    [TestClass]
    public class GPostTest
    {
        public GPostTest()
        {
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void bumpTest()
        {
            GThread parent = new GThread("bla", "bla", null);
            GPost post = new GPost("Subject", "content", null, parent);
            Assert.IsTrue(post.ModifiedDate.Equals(post.PublishDate));
            Assert.IsTrue(parent.ModifiedDate.Equals(parent.PublishDate));
            DateTime postDate1 = post.ModifiedDate;
            DateTime parentDate1 = parent.ModifiedDate;
            for (int i = 0; i < 10000000; i++) ;
            post.bump();
            DateTime postDate2 = post.ModifiedDate;
            DateTime parentDate2 = parent.ModifiedDate;
            Assert.IsTrue(postDate2.CompareTo(postDate1) > 0);
            Assert.IsTrue(parentDate2.CompareTo(parentDate1) > 0);
            for (int i = 0; i < 10000000; i++) ;
            post.bump();
            DateTime postDate3 = post.ModifiedDate;
            DateTime parentDate3 = parent.ModifiedDate;
            Assert.IsTrue(postDate3.CompareTo(postDate2) > 0);
            Assert.IsTrue(parentDate3.CompareTo(parentDate2) > 0);
        }

        [TestMethod]
        public void EqualsTest()
        {
            GPost p1 = new GPost(1, "Subject", "Content", null, null);
            GPost p2 = new GPost(2, "Subject", "Content", null, null);
            Assert.IsFalse(p1.Equals(p2));
            p2 = new GPost(1, p2);
            Assert.IsTrue(p1.Equals(p2));
        }
    }
}
